﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using TrivialPurfuit.Business;

namespace TrivialPurfuit.Presentation.BackDoor
{
    /// <summary>
    /// Interaction logic for BackDoorView.xaml
    /// </summary>
    public partial class BackDoorView : Window
    {
        public StateMachine stateMachine;

        public BackDoorView()
        {
            InitializeComponent();
        }

        public static void ShowNow(StateMachine stateMachine)
        {
            BackDoorView temp = new BackDoorView();
            temp.stateMachine = stateMachine;
            temp.Show();
        }

        private void UpButton_Click(object sender, RoutedEventArgs e)
        {
            if (GameBoard.Instance.Die.HasValue)
            {
                int result = GameBoard.Instance.Die.Value + 1;
                setDieValue(result);
            }
        }

        private void DownButton_Click(object sender, RoutedEventArgs e)
        {
            if (GameBoard.Instance.Die.HasValue)
            {
                int result = GameBoard.Instance.Die.Value - 1;
                setDieValue(result);
            }
        }

        private void setDieValue(int value)
        {

            if (value > 56)
                value = 56;

            if (value < 1)
                value = 1;

            GameBoard.Instance.Die = value;
            stateMachine.highlightPossibleDestinations();
            stateMachine.highlightPossibleDestinations();
            stateMachine.disableAllButtons();
            stateMachine.hideQuestionAndAnswer();
            stateMachine.setStateToChooseSpace();
        }
    }
}
